<?php
namespace catchAdmin\basics\model;

use catchAdmin\basics\model\search\OfficialSearch;
use catchAdmin\externalGoods\model\News;
use catcher\base\CatchModel;
use think\Exception;
use think\facade\Db;
use think\facade\Env;

class Official extends CatchModel
{
    use OfficialSearch;

    protected $name = 'db_official';
    protected $field = [
        'id',
        'long_url',
        'official_name',
        'status',
        'created_at',
        'updated_at',
        'deleted_at',
        'tenant_id',
        'creator_id',
        'deal',
        'last_page',
        'total_page',
        'retry_count'
    ];

    // 定义虚拟字段
//    protected $append = ['comment_count'];

    public function getList($tenant_id = 0)
    {
        $where = [];
        if($tenant_id !== 0){
            $where[]=['tenant_id','=',$tenant_id];
        }

        return $this
//            ->field('id,myData')
            ->catchSearch()
//            ->with('a')
//            ->withCount('articlesCount')
            ->where($where)
            ->order($this->aliasField('id'), 'desc')
//            ->order('comment_count','desc')
            ->paginate()
            ->each(function (&$item) {
//                $item['article_counts'] = (new News)->where('search_name',$item['official_name'])->count();
            });
    }

//    public function comments(){
//        return $this->hasMany(News::class,'search_name','official_name');
//    }
//
//    public function getCommentCountAttr()
//    {
//        return $this->comments()->count();
//    }
}
